package com.becca.cake.core.task.impl;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.becca.cake.core.constant.CommonConstants;
import com.becca.cake.core.socket.SocketMessage;
import com.becca.cake.core.task.Task;
import com.becca.cake.dao.order.OrderDAO;
import com.becca.cake.model.order.OrderModel;

/**
 * 确认订单数量
 * @copyright  尊星(上海)信息科技有限公司
 * @author hejinguo
 * @date 2016年6月19日 下午5:20:20
 */
public class OrderConfirmNumberDateTask implements Task {
    private static final Logger logger    = LoggerFactory
                                              .getLogger(OrderConfirmNumberDateTask.class);

    private OrderDAO            orderDAO;

    private boolean             executing = false;

    @Override
    public void doTask() {
        if (executing) {
            return;
        }
        executing = true;
        logger.info("order  query task start...");
        //step1:查询确认订单数量
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("orderStatus", OrderModel.ORDER_STATUS_CONFIRMED);
        int orderNumber = this.orderDAO.selcectOrderConfrimCount(paramMap);
        String data = "{subscriberType:'" + CommonConstants.USER_ORDER_CONFIRM_SENDMESSAGE
                      + "',content:'" + orderNumber + "'}";
        //消息推送
        SocketMessage.getInstance().sendOrderConCountMessage(data);
        executing = false;
        logger.info("order  query task end...");
    }

    public void setOrderDAO(OrderDAO orderDAO) {
        this.orderDAO = orderDAO;
    }

}
